import http from 'wechat-http'
// const baseUrl = `https://traincrm.cyberart.top/prod-api`
const baseUrl = `http://192.168.8.107:8086`
// const baseUrl = `http://192.168.8.27:8086`

http.baseURL = baseUrl;
(wx as any).httpBaseURL = baseUrl;
// 请求拦截器
http.intercept.request = (options)=>{
  const defaultHeader:{
    Authorization?:string
  } = {}
  defaultHeader.Authorization ='Bearer ' + getApp().getToken()
  options.header = Object.assign({},defaultHeader,options.header)
  return options
}
// 响应拦截器
http.intercept.response = ({data}:{data:any})=>{
  if(data.code === 401){
    wx.Utils.toast("用户身份过期，请重新登录")
    wx.navigateTo({
      url:'/pages/login/login'
    })
    // token失效可以执行refreshToken
  }
  return data
}
export default http